home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 7.2 KB | 259 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: HelloFrm.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "Hello.hpp"
-
- #ifndef FRAME_H
- #include "Frame.h"
- #endif
-
- #ifndef PART_H
- #include "Part.h"
- #endif
-
- #ifndef COMMANDS_H
- #include "Commands.h"
- #endif
-
- #ifndef CONTENT_H
- #include "Content.h"
- #endif
-
- // ----- Framework Layer -----
-
- #ifndef FWCONTXT_H
- #include "FWContxt.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWSELECT_H
- #include "FWSelect.h"
- #endif
-
- #ifndef FWGROWBX_H
- #include "FWGrowBx.h"
- #endif
-
- #ifndef FWSCLBAR_H
- #include "FWSclBar.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWMENU_H
- #include "FWMenu.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWALERT_H
- #include "FWAlert.h"
- #endif
-
- // ----- Graphic Includes -----
-
- #ifndef FWRECT_H
- #include "FWRect.h"
- #endif
-
- #ifndef FWTXTBOX_H
- #include "FWTxtBox.h"
- #endif
-
- #ifndef FWRECSHP_H
- #include "FWRecShp.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_ODDragItemIterator_xh
- #include <DgItmIt.xh>
- #endif
-
- //========================================================================================
- // Runtime Information
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfhello
- #endif
-
- FW_DEFINE_AUTO(CHelloFrame)
-
- //========================================================================================
- // CHelloFrame class
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CHelloFrame constructor
- //----------------------------------------------------------------------------------------
- CHelloFrame::CHelloFrame(Environment* ev, ODFrame* odFrame, FW_CPresentation* presentation, CHelloContent* content) :
- FW_CFrame(ev, odFrame, presentation, content->GetPart(ev)),
- FW_MDraggableFrame(ev, this),
- FW_MDroppableFrame(ev, this),
- fHelloContent(content)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloFrame destructor
- //----------------------------------------------------------------------------------------
-
- CHelloFrame::~CHelloFrame()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloFrame::DoMouseDown
- //----------------------------------------------------------------------------------------
-
- FW_Handled CHelloFrame::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
- {
- FW_Handled result = FW_kNotHandled;
-
- if (GetPresentation(ev)->GetSelection(ev)->IsMouseInDraggableItem(ev, this, theMouseEvent, FALSE) &&
- this->Drag(ev, theMouseEvent))
- {
- result = FW_kHandled;
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloFrame::DoAdjustMenus
- //----------------------------------------------------------------------------------------
-
- FW_Handled CHelloFrame::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar,
- FW_Boolean hasMenuFocus,
- FW_Boolean isRoot) // Override
- {
- FW_UNUSED(isRoot);
- if (hasMenuFocus)
- menuBar->EnableCommand(ev, kODCommandPaste, HasSupportedKindOnClipboard(ev));
-
- return FW_kNotHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloFrame::Draw
- //----------------------------------------------------------------------------------------
-
- void CHelloFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape) // Override
- {
- FW_CViewContext fc(ev, this, odFacet, invalidShape);
- FW_CRect invalidRect;
- fc.GetClipRect(invalidRect);
-
- FW_CRectShape::RenderRect(fc, invalidRect, FW_kFill, FW_kWhiteEraseInk);
-
- FW_CRect helloRect = GetBounds(ev);
-
- FW_CRectShape::RenderRect(fc, helloRect, FW_kFrame, FW_CInk(FW_kRGBBlack));
-
- // If this is a root part, draw the text centered horizontally and vertically.
- // If it's an embedded part, center the text horizontally, with word wrap and clipping.
- FW_TextBoxOptions options = FW_kTextBoxJustifyHCenter | FW_kTextBoxJustifyVCenter;
- if (!fHelloContent->IsTextCentered())
- {
- options |= FW_kTextBoxWordWrap;
- options |= FW_kTextBoxClipToBox;
- }
- FW_CTextBoxShape::RenderTextBox(
- fc,
- fHelloContent->GetTextData(),
- helloRect,
- FW_kSystemFont,
- options);
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloFrame::FrameShapeChanged
- //----------------------------------------------------------------------------------------
- // By default a FW_CFrame view is not refreshed entirely when resized.
- // You must decide if your content's appearance depends on the frame's size.
- // If it doesn't you don't need to override FrameShapeChanged().
- // Here we must redraw the whole frame everytime because the text is centered.
-
- void CHelloFrame::FrameShapeChanged(Environment* ev)
- {
- FW_CFrame::FrameShapeChanged(ev);
-
- this->Invalidate(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloFrame::NewClipboardCommand
- //----------------------------------------------------------------------------------------
-
- FW_CClipboardCommand* CHelloFrame::NewClipboardCommand(Environment* ev, ODCommandID commandID)
- {
- return FW_NEW(CHelloEditCommand, (ev, commandID, fHelloContent, this));
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloFrame::NewDragCommand
- //----------------------------------------------------------------------------------------
-
- FW_CDragCommand* CHelloFrame::NewDragCommand(Environment *ev,
- FW_CFrame* theFrame,
- const FW_CMouseEvent& theMouseEvent)
- {
- FW_UNUSED(theMouseEvent);
- return FW_NEW(CHelloDragCommand, (ev, fHelloContent, theFrame));
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloFrame::NewDropCommand
- //----------------------------------------------------------------------------------------
-
- FW_CDropCommand* CHelloFrame::NewDropCommand(Environment* ev,
- FW_CFrame* frame,
- ODDragItemIterator* dropInfo,
- ODFacet* odFacet,
- const FW_CPoint& dropPoint)
- {
- FW_UNUSED(frame);
- return FW_NEW(CHelloDropCommand, (ev, fHelloContent, this, dropInfo, odFacet, dropPoint));
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloFrame::CreateSubViews
- //----------------------------------------------------------------------------------------
-
- void CHelloFrame::CreateSubViews(Environment* ev)
- {
- // Create a GrowBox only in root frame
- // Note: you do not need CreateSubViews if the views are defined in resources.
- // See the Container or Form samples.
-
- if (this->IsRoot(ev))
- {
- FW_CRect frameRect = GetBounds(ev);
- FW_CPoint sbSize = FW_CScrollBar::GetDefaultScrollBarSize();
- frameRect.right -= sbSize.x;
- frameRect.bottom -= sbSize.y;
-
- FW_CGrowBox* growBox = new FW_CGrowBox(ev, this, 0, frameRect.BotRight());
- }
- }
-